package com.example.springboot.controller;

import com.example.springboot.entity.Rydk;
import com.example.springboot.entity.User;
import com.example.springboot.mapper.RydkMapper;
import com.example.springboot.service.RydkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/rydk")
public class RydkController {
    @Autowired
    private RydkMapper rydkMapper;
    @Autowired
    private RydkService rydkService;
    @PostMapping("/add")
    public Map<String,Object> save(@RequestBody Rydk rydk){
        Map<String,Object> res=new HashMap<>();
        if(rydkService.rydk(rydk) == 1){
            res.put("code",200);
            res.put("msg","操作成功");
        }
        return  res;
    }
    @GetMapping("/index")
    public Map<String, Object> index1(@RequestParam Integer pageNum, @RequestParam Integer pageSize,@RequestParam String name){
        pageNum=(pageNum-1)*pageSize;
        List<Rydk> data= rydkMapper.selectPage(pageNum,pageSize,name);
        Integer total = rydkMapper.selectTotal(name);
        Map<String,Object> res=new HashMap<>();
        res.put("data",data);
        res.put("total",total);

        return res;

//        return userMapper.findAll();
    }
}
